using System;
using System.Xml.Serialization;
using AndyPike.Unfuddle.Contracts;

namespace AndyPike.Unfuddle.Entities.Tickets
{
	/// <summary>
	/// Represents an Unfuddle Ticket entity
	/// </summary>
	[XmlRoot("ticket")]
	public class Ticket : IEntity
	{
		/// <summary>
		/// 
		/// </summary>
		[XmlElement("assignee-id")]
		public int? AssigneeId { get; set; }

		/// <summary>
		/// 
		/// </summary>
		[XmlElement("component-id")]
		public int? ComponentId { get; set; }

		/// <summary>
		/// 
		/// </summary>
		[XmlElement("description")]
		public string Description { get; set; }

		/// <summary>
		/// 
		/// </summary>
		[XmlElement("due-on")]
		public DateTime? DueOn { get; set; }

		/// <summary>
		/// 
		/// </summary>
		[XmlElement("hours-estimate-current")]
		public float HoursEstimateCurrent { get; set; }

		/// <summary>
		/// 
		/// </summary>
		[XmlElement("hours-estimate-initial")]
		public float HoursEstimateInitial { get; set; }

		/// <summary>
		/// 
		/// </summary>
		[XmlElement("id")]
		public int Id { get; set; }

		/// <summary>
		/// 
		/// </summary>
		[XmlElement("milestone-id")]
		public int? MilestoneId { get; set; }

		/// <summary>
		/// 
		/// </summary>
		[XmlElement("number")]
		public int Number { get; set; }

		/// <summary>
		/// 
		/// </summary>
		[XmlElement("priority")]
        public TicketPriority Priority { get; set; }

		/// <summary>
		/// 
		/// </summary>
		[XmlElement("project-id")]
		public int ProjectId { get; set; }

		/// <summary>
		/// 
		/// </summary>
		[XmlElement("reporter-id")]
		public int ReporterId { get; set; }

		/// <summary>
		/// 
		/// </summary>
		[XmlElement("resolution")]
		public TicketResolution Resolution { get; set; }

		/// <summary>
		/// 
		/// </summary>
		[XmlElement("resolution-description")]
		public string ResolutionDescription { get; set; }

		/// <summary>
		/// 
		/// </summary>
		[XmlElement("severity-id")]
		public int? SeverityId { get; set; }

		/// <summary>
		/// 
		/// </summary>
		[XmlElement("status")]
		public TicketStatus Status { get; set; }

		/// <summary>
		/// 
		/// </summary>
		[XmlElement("summary")]
		public string Summary { get; set; }

		/// <summary>
		/// 
		/// </summary>
		[XmlElement("version-id")]
		public int? VersionId { get; set; }

		/// <summary>
		/// 
		/// </summary>
		[XmlElement("created-at")]
		public DateTime CreatedAt { get; set; }

		/// <summary>
		/// 
		/// </summary>
		[XmlElement("updated-at")]
        public DateTime UpdatedAt { get; set; }

        /// <summary>
        /// Validates an Unfuddle Ticket entity depending on the current validation context
        /// </summary>
        public virtual void Validate(EntityValidationContext context)
        {
            if (context == EntityValidationContext.Creating)
                GuardAgainst.EntityPropertyOutsideRange(this, "Id", Id, 0, 0);

            if (context == EntityValidationContext.Updating)
                GuardAgainst.EntityPropertyOutsideRange(this, "Id", Id, 1, int.MaxValue);

            GuardAgainst.EntityPropertyNullOrEmpty(this, "Summary", Summary);
            GuardAgainst.EntityPropertyOutsideRange(this, "ProjectId", ProjectId, 1, int.MaxValue);
        }
	}
}
